/**以下2个方法是将上传的图片在本地压缩成base64编码*/
function getUrl(fil,id,fid) {
            var Cnv = document.getElementById('myCanvas'+fid);
            var Cntx = Cnv.getContext('2d');//获取2d编辑容器
            var imgss =   new Image();
            var agoimg=document.getElementById("ago"+fid);
            //alert(fil.length)
            for (var intI = 0; intI < fil.length; intI++) {
                var tmpFile = fil[intI];
                var reader = new FileReader();
                reader.readAsDataURL(tmpFile);
                reader.onload = function (e) {
                	//alert("a");
                    url = e.target.result;
                    //console.log(url.length);
                    imgss.src = url;
                    agoimg.src=url;
                    agoimg.onload = function () {
                    	
                             Cnv.height =imgss.height;
                             Cnv.width= imgss.width ;
                             Cntx.drawImage(agoimg, 0, 0,imgss.width,imgss.height);
                    	 var Pic = document.getElementById("myCanvas"+fid).toDataURL("image/png");
                    	 //alert(Pic.length);
						var maxSize = 4000000;//4M
                    	 if(Pic.length>=maxSize)
                    	 {
                    		// alert(2);
                    		 //等比缩放
                             var m = maxSize /Pic.length;
                            // alert(m);
                              Cnv.height =imgss.height*m;//该值影响缩放后图片的大小
                              Cnv.width= imgss.width*m ;
                              //img放入画布中
                              //设置起始坐标，结束坐标
                              Cntx.drawImage(agoimg, 0, 0, Cnv.width,Cnv.height);
                             // alert(4);
                    	 }
                    	 
                       
                    }
                }
            }
        }

function  pressss2(fid,urll,pictureName,sName,file){//
		var typep=$("#type"+fid).val();
		var materialname=$("#materialname"+fid).val();
    //获取canvas压缩后的图片数据
    var Pic = document.getElementById("myCanvas"+fid).toDataURL("image/png");
	//var urll = "<c:url value='/api/owner_dog/uploadBase64Img'/>";
   // alert(Pic.length);
    var imgs;
    if(file==0)
    	{
    		if(materialname==" "||materialname==null)
    		{
    			imgs =document.getElementById("pzctrl"+fid);
    		}
    		else{
    			imgs =document.getElementById("file"+fid);
    			}
    	}
    else
    	{
    	imgs=document.getElementById(file);
    	}
    if(file==0)
    {
    	imgs.src =Pic;
        //上传
        // 去除多余，得到base64编码的图片字节流
        Pic = Pic.replace(/^data:image\/(png|jpg);base64,/, "");
        //console.log(Pic.length);
       $.ajax({
    	 url:urll,
    	 type : 'POST',
    	 dataType : 'json',
    	 async:false,
    	 data:{
    	 	"base64" :Pic,
    	 	"imgname":pictureName,
    	 	"type":typep,
    	 	"name":sName,
    	 	"materialname":materialname
    	 },
    	 success: function (resp, status, xhr) {
    			//alert(resp.msg); 
    		 alert("提交成功"); 
    		if(fid==0){
    		    isuploadimg0=true;
    		 }
    		 if(fid==1){
    			 isuploadimg1=true;
    		 }
    		 if(fid==2){
    			 isuploadimg2=true;
    		 }
    		 if(fid==3){
    			 isuploadimg3=true;
    		 }
    		 if(fid==4){
    			 isuploadimg4=true;
    		 }
    		 if(fid==5){
    			 isuploadimg5=true;
    		 }
    		 if(fid==6){
    			 isuploadimg6=true;
    		 }
    	 },
    	 complete : function(XMLHttpRequest,status){
    		 unlockBtn1(fid);
    	 }
     });
    }
    else
    	{
    	imgs.src =Pic ;
    	//上传
    	// 去除多余，得到base64编码的图片字节流
    	Pic = Pic.replace(/^data:image\/(png|jpg);base64,/, "");
    	//console.log(Pic.length);
    	$.ajax({
    	 url:urll,
    	 type : 'POST',
    	 dataType : 'json',
    	 async:false,
    	 data:{
    	 	"base64" :Pic,
    	 	"imgname":pictureName,
    	 	"type":fid
    	 },
    	 success: function (resp, status, xhr) {
 			//alert(resp.msg);
    		 alert("提交成功"); 
 		if(fid==0){
 		    isuploadimg0=true;
 		 }
 		 if(fid==1){
 			 isuploadimg1=true;
 		 }
 		 if(fid==2){
 			 isuploadimg2=true;
 		 }
 		 if(fid==3){
 			 isuploadimg3=true;
 		 }
 		 if(fid==4){
 			 isuploadimg4=true;
 		 }
 		 if(fid==5){
 			 isuploadimg5=true;
 		 }
 		 if(fid==6){
 			 isuploadimg6=true;
 		 }
 	 },
 	 complete : function(XMLHttpRequest,status){
 		 unlockBtn1(fid);
 	 }
    	});
    	}
 
    
    
   
    //可以用ajax提交到后台，提交后可以直接存数据库，也可以保存成图片，此处略，
    //技术交流495120021

}
/**
function  pressss1(fid,urll,pictureName){//
	var typep=$("#type"+fid).val();
	var materialname=$("#materialname"+fid).val();
//获取canvas压缩后的图片数据
var Pic = document.getElementById("myCanvas"+fid).toDataURL("image/png");
//var urll = "<c:url value='/api/owner_dog/uploadBase64Img'/>";
var imgs =document.getElementById("file"+fid);
imgs.src =Pic ;
//上传
// 去除多余，得到base64编码的图片字节流
Pic = Pic.replace(/^data:image\/(png|jpg);base64,/, "");
//console.log(Pic.length);
$.ajax({
 url:urll,
 type : 'POST',
 dataType : 'json',
 async:false,
 data:{
 	"base64" :Pic,
 	"imgname":pictureName,
 	"type":typep,
 	"name":sName,
 	"materialname":materialname
 },
 success: function (resp, status, xhr) {
		 alert(resp.msg);
	if(fid==0){
	    isuploadimg0=true;
	 }
	 if(fid==1){
		 isuploadimg1=true;
	 }
	 if(fid==2){
		 isuploadimg2=true;
	 }
	 if(fid==3){
		 isuploadimg3=true;
	 }
	 if(fid==4){
		 isuploadimg4=true;
	 }
	 if(fid==5){
		 isuploadimg5=true;
	 }
	 if(fid==6){
		 isuploadimg6=true;
	 }
 },
 complete : function(XMLHttpRequest,status){
	 unlockBtn1(fid);
 }
});

//可以用ajax提交到后台，提交后可以直接存数据库，也可以保存成图片，此处略，
//技术交流495120021

}
*/
/**
function  pressss3(fid,urll,pictureName,file){//
//获取canvas压缩后的图片数据
var Pic = document.getElementById("myCanvas"+fid).toDataURL("image/png");
//var urll = "<c:url value='/api/owner_dog/uploadBase64Img'/>";
var imgs =file;
imgs.src =Pic ;
//上传
// 去除多余，得到base64编码的图片字节流
Pic = Pic.replace(/^data:image\/(png|jpg);base64,/, "");
//console.log(Pic.length);
$.ajax({
 url:urll,
 type : 'POST',
 dataType : 'json',
 async:false,
 data:{
 	"base64" :Pic,
 	"imgname":pictureName,
 	"type":fid
 }
});

//可以用ajax提交到后台，提交后可以直接存数据库，也可以保存成图片，此处略，
//技术交流495120021

}*/